﻿//------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Text;
using System.Xml;
using Microsoft.ResourceManagement.Samples.ResourceManagementClient.ResourceManagement;
using Microsoft.ResourceManagement.Samples.ResourceManagementClient.Utilities;

namespace Microsoft.ResourceManagement.Samples.ResourceManagementClient.WSTransfer
{
    /// <summary>
    /// This class encapsulates a WS-Transfer GetResponse.
    /// Please read the spec http://www.w3.org/Submission/WS-Transfer/
    /// 
    /// A client receives a GetResponse with the individual element.
    /// 
    /// Please note our implementation does not use this class to deserialize
    /// the GetResponse.  We include the class for documentation only.
    /// </summary>
    public class GetResponse
    {
        private ResourceManagementObject resourceManagementObject;
        private List<XmlNode> bodyElements;

        public GetResponse()
        {
            this.bodyElements = new List<XmlNode>();
        }

        
        // list so the serializer can add elements
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists"), XmlAnyElement(Namespace = Constants.NamespaceResourceManagement)]
        public List<XmlNode> BodyElements
        {
            get
            {
                return this.bodyElements;
            }
            set
            {
                this.bodyElements = value;
            }
        }

        
        public ResourceManagementObject Object
        {
            get
            {
                if (null == resourceManagementObject)
                {
                    if (bodyElements.Count > 0)
                    {
                        resourceManagementObject = ResourceManagementObjectFactory.CreateObject(bodyElements[0]);
                    }
                }
                return resourceManagementObject;
            }
        }
    }
}
